package com.ssy.lingxi.member.merchant.controller.web;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.dataauth.annotation.member.MemberAuth;
import com.ssy.lingxi.member.merchant.api.model.vo.inner.response.MemberManageQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.MemberNameVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.SubMemberIdRoleIdVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.request.UserPageVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.MemberIdAndNameVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.RoleIdAndNameVO;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.UserQueryVO;
import com.ssy.lingxi.member.merchant.model.vo.manage.request.*;
import com.ssy.lingxi.member.merchant.model.vo.manage.response.*;
import com.ssy.lingxi.member.merchant.service.web.IMemberManageService;
import org.springframework.http.HttpHeaders;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @menu 平台后台及业务平台 - 通用会员查询服务接口
 * @author 万宁
 * @version 2.0.0
 * @date 2020-06-05
 */
@RestController
@RequestMapping("/member/manage")
public class MemberManageController {
    @Resource
    private IMemberManageService memberManageService;

    /**
     * 根据角色类型，查询角色列表
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/role/all", method = RequestMethod.GET)
    public Wrapper<List<RoleIdAndNameVO>> allRoles(@RequestHeader HttpHeaders headers, @Valid MemberManageRoleTypeVO roleTypeVO) {
        return memberManageService.allRoles(headers, roleTypeVO);
    }

    /**
     * 根据当前登录会员，查询下级会员角色列表
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/role/sub/list", method = RequestMethod.GET)
    public Wrapper<List<RoleIdAndNameVO>> getSubRoleListByMember(@RequestHeader HttpHeaders headers) {
        return memberManageService.getSubRoleListByMember(headers);
    }

    /**
     * 查询所有下级"渠道会员"角色，返回Id和角色名称列表
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/role/list", method = RequestMethod.GET)
    public Wrapper<List<RoleIdAndNameVO>> listRoles(@RequestHeader HttpHeaders headers) {
        return memberManageService.listRoles(headers);
    }

    /**
     * 根据会员名称、模糊分页查询下级会员列表
     * <p>平台规则设置 - 新增支付策略</p>
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByName(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pageLowerMembersByName(headers, pageVO);
    }

    /**
     * 根据下级会员名称、下级会员角色Id，模糊分页查询下级会员列表
     * @param headers  HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/page/bynamerole", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByNameAndRole(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameAndRoleIdVO pageVO) {
        return memberManageService.pageLowerMembersByNameAndRole(headers, pageVO);
    }

    /**
     * 查询上级渠道会员（包括渠道企业、渠道个人）列表，返回会员Id和名称
     * @param headers  HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/channel/upper/list", method = RequestMethod.GET)
    public Wrapper<List<MemberIdAndNameVO>> listUpperChannelMembers(@RequestHeader HttpHeaders headers) {
        return memberManageService.listUpperChannelMembers(headers);
    }

    /**
     * 查询所有“下级渠道会员”的角色，返回Id和角色名称列表
     * @param headers  HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/channel/lower/role/list", method = RequestMethod.GET)
    public Wrapper<List<RoleIdAndNameVO>> listLowerChannelRoles(@RequestHeader HttpHeaders headers) {
        return memberManageService.listLowerChannelRoles(headers);
    }

    /**
     * 根据下级渠道会员名称、下级渠道会员角色Id，模糊分页查询下级渠道会员列表
     * @param headers  HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/channel/lower/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerChannelMembersByNameAndRole(@RequestHeader HttpHeaders headers, @Valid MemberManageChannelPageVO pageVO) {
        return memberManageService.pageLowerChannelMembersByNameAndRole(headers, pageVO);
    }

    /**
     * 根据下级会员名称，模糊分页查询会员角色为服务提供者的下级会员列表
     * @param headers  HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/provider/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerProviderMembersByName(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberManageNameWithExcludePageVO pageVO) {
        return memberManageService.pageLowerProviderMembersByName(headers, pageVO);
    }

    /**
     * 根据下级会员名称，模糊分页查询会员角色为服务消费者的下级会员列表（带排除列表）
     * @param headers  HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/consumer/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerConsumerMembersByName(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberManageNameWithExcludePageVO pageVO) {
        return memberManageService.pageLowerConsumerMembersByName(headers, pageVO);
    }

    /**
     * 根据下级会员名称，模糊分页查询会员角色为服务消费者的下级会员列表
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/lower/consumer/member/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerConsumerMembersByName(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pageLowerConsumerMembersByName(headers, pageVO);
    }

    /**
     * 根据下级会员名称，模糊分页查询会员角色为服务提供者的下级“企业会员”列表
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/lower/merchant/provider/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerMerchantProviderMembersByName(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pageLowerMerchantProviderMembersByName(headers, pageVO);
    }

    /**
     * 根据会员名称等条件+商城类型分页查询下属会员列表
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/bymall/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMemberByNameAndMallType(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameAndMallTypeVO pageVO) {
        return memberManageService.pageMemberByNameAndMallType(headers, pageVO);
    }

    /**
     * 根据上级会员Id和上级会员角色Id，以及当前用户，查询价格权益参数设置
     * @param headers HttpHeaders信息
     * @param upperVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/upper/credit/param/get", method = RequestMethod.GET)
    public Wrapper<MemberManageMemberCreditParameterVO> getUpperMemberCreditParameter(@RequestHeader HttpHeaders headers, @Valid MemberManageUpperMemberAndRoleVO upperVO) {
        return memberManageService.getUpperMemberCreditParameter(headers, upperVO);
    }

    /**
     * 根据当前用户（上级会员），查询下级会员的价格权益参数设置
     * @param headers HttpHeaders信息
     * @param subVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/lower/credit/param/get", method = RequestMethod.GET)
    public Wrapper<MemberManageMemberCreditParameterVO> getLowerMemberCreditParameter(@RequestHeader HttpHeaders headers, @Valid SubMemberIdRoleIdVO subVO) {
        return memberManageService.getLowerMemberCreditParameter(headers, subVO);
    }


    /**
     * 根据名称，模糊分页查询下级渠道会员列表
     * @param headers HttpHeaders信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/channel/page/byname", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerChannelMembersByName(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameAndRoleIdVO pageVO) {
        return memberManageService.pageLowerChannelMembersByNameAndRoleId(headers, pageVO);
    }

    /**
     * 根据下单类型和会员名称，模糊分页查询会员
     * @param headers HttpHeaders信息
     * @param typeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/all/page/byordertype", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByOrderTypeAndName(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByOrderTypeAndNameVO typeVO) {
        return memberManageService.pageMembersByOrderTypeAndName(headers, typeVO);
    }

    /**
     * 分页查询会员列表页面搜索条件内容
     * @param headers HttpHeaders信息
     * @return 查询结果
     */
    @RequestMapping(value = "/pageitems", method = RequestMethod.GET)
    public Wrapper<MemberManageSearchConditionVO> getPageSearchConditions(@RequestHeader HttpHeaders headers, MemberManageMemberItemVO itemVO) {
        return memberManageService.getPageSearchConditions(headers, itemVO);
    }

    /**
     * “新增仓位存储”：根据商城类型分页查询会员
     * @param headers HttpHeaders信息
     * @param typeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/all/page/byshoptype", method = RequestMethod.POST)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByShopType(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberManagePageByShopTypeVO typeVO) {
        return memberManageService.pageMembersByShopType(headers, typeVO);
    }

    /**
     * 分页查询角色为“服务提供者”的平台会员列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/all/provider/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByServiceProviderRole(@RequestHeader HttpHeaders headers, @Valid MemberManagePageVO pageVO) {
        return memberManageService.pageMembersByServiceProviderRole(headers, pageVO);
    }

    /**
     * 分页查询角色为“服务消费者”的平台会员列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/all/consumer/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageMembersByServiceConsumerRole(@RequestHeader HttpHeaders headers, @Valid MemberManagePageVO pageVO) {
        return memberManageService.pageMembersByServiceConsumerRole(headers, pageVO);
    }

    /**
     * 根据会员名称，分页查询角色类型为服务提供者的平台商户会员
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/provider/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pagePlatformServiceProviderMerchantMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pagePlatformServiceProviderMerchantMember(headers, pageVO);
    }

    /**
     * 根据会员名称，分页查询角色类型为服务提供者的平台企业会员（非企业个人会员）
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/enterprise/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pagePlatformServiceProviderEnterpriseMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pagePlatformServiceProviderEnterpriseMember(headers, pageVO);
    }

    /**
     * 根据会员名称，分页查询角色为服务提供者的上级会员列表
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/upper/provider/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageUpperProviderMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageUpperProviderMember(headers, pageByNameVO);
    }

    /**
     * 根据会员名称，分页查询角色为服务提供者的上级会员列表(增加条件会员等级类型为商户会员)
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/upper/providerMerchant/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageUpperProviderMerchantMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageUpperProviderMerchantMember(headers, pageByNameVO);
    }

    /**
     * 根据会员名称，分页查询角色为当前会员所属的下属会员且角色类型为服务提供的会员
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/lower/providerMerchant/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageLowerProviderMerchantMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageLowerProviderMerchantMember(headers, pageByNameVO);
    }

    /**
     * 根据会员名称，分页查询上级会员列表
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/upper/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageUpperMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageUpperMember(headers, pageByNameVO);
    }


    /**
     * “售后能力 - 提交换货申请单” - 选择供应会员
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/aftersale/replace/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageAfterSaleMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageAfterSaleMember(headers, pageByNameVO);
    }

    /**
     * “物流能力 - 新增物流公司” - 选择物流服务商
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/logistics/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberManageQueryVO>> pageLogisticSubMember(@RequestHeader HttpHeaders headers, @RequestBody @Valid MemberManagePageLogisticsVO pageVO) {
        return memberManageService.pageLogisticSubMember(headers, pageVO);
    }

    /**
     * 分页查询会员下属用户
     * @param headers Http头部新
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/users/page", method = RequestMethod.GET)
    public Wrapper<PageData<UserQueryVO>> pageUsers(@RequestHeader HttpHeaders headers, @Valid UserPageVO pageVO) {
        return memberManageService.pageUsers(headers, pageVO);
    }

    /**
     * "适用会员等级", 查询等级配置详情
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/marketing/suitable/level/config/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberSuitableLevelConfigVO>> pageMarketingSuitableLevelConfig(@RequestHeader HttpHeaders headers, @Valid MemberLevelDetailPageVO pageVO) {
        return memberManageService.pageMarketingSuitableLevelConfig(headers, pageVO);
    }

    /**
     * “营销能力” - 获取适用会员查询条件
     * @param headers Http头部信息
     * @param typeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/marketing/suitable/page/items", method = RequestMethod.POST)
    public Wrapper<MemberSuitableConditionVO> getMarketingSuitableCondition(@RequestHeader HttpHeaders headers, @RequestBody(required = false) SuitableMemberTypeVO typeVO) {
        return memberManageService.getMarketingSuitableCondition(headers, typeVO);
    }

    /**
     * “营销能力” - 查询适用会员(分页)
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/marketing/suitable/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberSuitableVO>> pageMarketingSuitable(@RequestHeader HttpHeaders headers, @RequestBody @Valid MarketingSuitablePageVO pageVO) {
        return memberManageService.pageMarketingSuitable(headers, pageVO);
    }

    /**
     * “平台营销” - 获取适用会员查询条件
     * @param headers Http头部信息
     * @param ageTypeVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/marketing/suitable/page/items", method = RequestMethod.POST)
    public Wrapper<PlatformMemberSuitableConditionVO> getPlatformMarketingSuitableCondition(@RequestHeader HttpHeaders headers, @RequestBody(required = false) PlatformSuitableMemberTypeVO ageTypeVO) {
        return memberManageService.getPlatformMarketingSuitableCondition(headers, ageTypeVO);
    }

    /**
     * “平台营销” - 查询适用会员(分页)
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/marketing/suitable/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberSuitableVO>> pagePlatformMarketingSuitable(@RequestHeader HttpHeaders headers, @RequestBody @Valid MarketingSuitablePageVO pageVO) {
        return memberManageService.pagePlatformMarketingSuitable(headers, pageVO);
    }

    /**
     * “平台营销” - 获取邀请报名参加会员查询条件
     * @param headers Http头部信息
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/marketing/invite/page/items", method = RequestMethod.POST)
    public Wrapper<PlatformMemberInviteConditionVO> getPlatformMarketingInviteCondition(@RequestHeader HttpHeaders headers) {
        return memberManageService.getPlatformMarketingInviteCondition(headers);
    }

    /**
     * “平台营销” - 查询邀请报名参加会员列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/platform/marketing/invite/page", method = RequestMethod.POST)
    public Wrapper<PageData<PlatformMarketingInvitePageVO>> pagePlatformMarketingInvite(@RequestHeader HttpHeaders headers, @RequestBody @Valid PlatformMarketingInviteQueryVO pageVO) {
        return memberManageService.pagePlatformMarketingInvite(headers, pageVO);
    }

    /**
     * “订单服务 - 代客下单” - 查询角色为服务消费者的平台会员列表
     * @param headers Http头部信息
     * @param nameVO 接口参数
     * @return 查询结果
     */
    @MemberAuth
    @RequestMapping(value = "/order/agent/members", method = RequestMethod.GET)
    public Wrapper<List<MemberManageQueryVO>> findPlatformConsumerMembers(@RequestHeader HttpHeaders headers, @Valid MemberManageNameVO nameVO) {
        return memberManageService.findPlatformConsumerMembers(headers, nameVO);
    }

    /**
     * “订单服务 - 新增现货采购订单” - 查询会员列表
     * @param headers Http头部信息
     * @param pageVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/order/buyer/members", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageBuyerOrderMembers(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageVO) {
        return memberManageService.pageBuyerOrderMembers(headers, pageVO);
    }

    /**
     * 根据会员名称，分页查询角色为服务消费者的上级会员列表
     * @param headers Http头部信息
     * @param pageByNameVO 接口参数
     * @return 查询结果
     */
    @RequestMapping(value = "/upper/consumerMerchant/page", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> pageUpperConsumerMerchantMember(@RequestHeader HttpHeaders headers, @Valid MemberManagePageByNameVO pageByNameVO) {
        return memberManageService.pageUpperConsumerMerchantMember(headers, pageByNameVO);
    }

    /**
     * 选择采购会员 功能
     * @param headers Http头部信息
     * @param nameVO  接口参数
     * @return 采购会员信息
     */
    @RequestMapping(value = "/buyerMember", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> buyerMemberInfo(@RequestHeader HttpHeaders headers, @Valid MemberNameVO nameVO) {
        return memberManageService.buyerMemberInfo(headers, nameVO);
    }

    /**
     * 选择供应会员 功能
     * @param headers Http头部信息
     * @param nameVO  接口参数
     * @return 供应会员信息
     */
    @RequestMapping(value = "/supplyMember", method = RequestMethod.GET)
    public Wrapper<PageData<MemberManageQueryVO>> supplyMemberInfo(@RequestHeader HttpHeaders headers, @Valid MemberNameVO nameVO) {
        return memberManageService.supplyMemberInfo(headers, nameVO);
    }
}
